package com.itheima.controller.backend;


import com.itheima.common.entity.Result;
import com.itheima.controller.backend.security.SpringSecurityUserService;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private SpringSecurityUserService service;

    /**
     * 获取登录用户名
     * @return
     */
    @GetMapping("/getLoginUsername")
    public Result getLoginUsername() {
        String username = null;
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication != null) {
            username = authentication.getName();
        }
        return new Result(true, "登录成功", username);
    }
}
